#!/usr/bin/perl

print <<EOL;
#!/usr/bin/python
# -*- coding: utf-8 -*-

import GF

Type   = lambda args, cat: (args, cat)
Apply  = lambda fun, args: (fun, tuple(args))
PArg   = lambda cat: cat
Coerce = lambda arg: arg
CncFun = lambda name, lins: (name, lins)
SymCat = lambda i, lbl: (GF.SymCat, i, lbl)
SymKS  = lambda *tokens: (GF.SymKSP, list(tokens), [])
SymKP  = lambda tokens, alts: (GF.SymKSP, list(tokens), list(alts))
Alt    = lambda tokens, follows: (list(tokens), list(follows))
SymLit = lambda i, lbl: (GF.SymLit, i, lbl)

EOL

while (<>) {
  s/^var //;
  s/\bnew //g;
  s/\b(\w*[^\W\d]\w*):/"$1":/g;
  # s/\bKS\("/KS(u"/g;
  s/("[^"]*")/u$1/g;
  s/GF(Grammar|Abstract|Concrete)/GF.$1/g;

  # s/[}{]/\n$&/g;
  s/u"\w+": *GF\./\n$&/g;
  s/u"\w+": *Type\(/\n    $&/g;
  s/\d+: *\[(Apply|Coerce)\(/\n    $&/g;
  s/CncFun\(/\n    $&/g;
  s/\[Sym(KS|KP|Cat)\(/\n    $&/g;
  s/u"\w+": *\{u"s":/\n    $&/g;
  print;
}

